using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ShivamEMR.Model.Domain.PersonDomain;
using ShivamEMR.Model.DataInterfaces.PersonDataInterf;
using ShivamEMR.Model;
using ShivamEMR.Web.Models;
//using ShivamEMR.Web.Areas.Person.Models;

namespace ShivamEMR.Web.Areas.Person.Controllers
{   
    public class SexController : Controller
    {
		private readonly ISexRepository sexRepository;

		// If you are using Dependency Injection, you can delete the following constructor
        public SexController() 
        {
            sexRepository = Registry.RepositoryFactory.GetSexRepository();
        }

        public SexController(ISexRepository sexRepository)
        {
			this.sexRepository = sexRepository;
        }

        //
        // GET: /Sex/
        //[CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Index()
        {
           // return View(sexRepository.AllIncluding(sex => sex.Persons));
            return View(sexRepository.All);
        }

        //
        // GET: /Sex/Details/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ViewResult Details(int id)
        {
            return View(sexRepository.Find(id));
        }

        //
        // GET: /Sex/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Sex/Create
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Create(Sex sex)
        {
            if (ModelState.IsValid) {
                sexRepository.Create(sex);
                sexRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }
        
        //
        // GET: /Sex/Edit/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Edit(int id)
        {
             return View(sexRepository.Find(id));
        }

        //
        // POST: /Sex/Edit/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost]
        public ActionResult Edit(Sex sex)
        {
            if (ModelState.IsValid) {
                sexRepository.Update(sex);
                sexRepository.Save();
                return RedirectToAction("Index");
            } else {
				return View();
			}
        }

        //
        // GET: /Sex/Delete/5
 [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        public ActionResult Delete(int id)
        {
            return View(sexRepository.Find(id));
        }

        //
        // POST: /Sex/Delete/5
        [CustomAuthorizeAttribute(RequiredRight = "Admin")]
        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {
            //sexRepository.Delete(id);
            var sex = sexRepository.Find(id);
              sexRepository.Delete(sex);
            sexRepository.Save();

            return RedirectToAction("Index");
        }
    }
}

